<?php
/**
 * Created by PhpStorm.
 * User: wx
 * Date: 2019/5/17
 * Time: 11:50
 */
namespace app\admin\dbhelp;

class DbHelper extends \think\Model implements IDbHelper
{
    protected $name;//表字段
    public function __set($name, $value)
    {
        $this->name = $value;
    }

    /**
     * @param $id
     * @param string $field 需要查询的字段
     * @return array|false|PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($id,$field='*')
    {
        return $this->field($field)->where('id',$id)->find();
    }
    public function getAll($field='*',$where=null,$order='id desc')
    {
        $list = $this->field($field)->where($where)->order($order)->paginate(10);
        return $list;
    }
    public function edit($id,$data)
    {
        return $this->where('id',$id)->update($data);
    }
    public function del($id)
    {
        return $this->where('id',$id)->delete();
    }
    public function add($data)
    {
        return $this->insert($data);
    }
    public function getCount($where=null)
    {
        if($where)
        {
            return $this->where($where)->count();
        }else{
            return $this->count();
        }
    }
}